
import numpy as np

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
# from proplot import rc
plt.rcParams['axes.unicode_minus'] = False  # -
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签


fontsize = 20


pdf_name = '3-2-b'

# 数据
labels = ['BGL', 'HDFS']
group_name = ['Drain', 'Spell', 'AEL']
group_data = [
    [0.80, 0.76],
    [0.98, 0.53],
    [0.79, 0.83],
]


colors = ['blue', 'green', 'orange', 'red']
hatches = ['/', '\\', '-', '|']

# 绘图
xpixels=400
ypixels=300
dpi=60

xinch = xpixels / dpi
yinch = ypixels / dpi
fig, ax = plt.subplots(1, 1, figsize=(xinch, yinch))
index = np.arange(len(labels))
bar_width = 0.2
opacity = 0.8

for i, data in enumerate(group_data):
    bars = plt.bar(index + i * bar_width, data, bar_width,
            alpha=opacity,
            label=group_name[i],
            color=colors[i], hatch=hatches[i], )
    for bar in bars:
        height = bar.get_height()
        ax.text(bar.get_x() + bar.get_width()/2., height, height,
                ha='center', va='bottom', fontsize=fontsize*0.5)

# plt.xlabel('数据集', fontsize=fontsize)
# plt.ylabel('GA评估分值', fontsize=fontsize)
# plt.title('Scores by dataset and method')
plt.xticks(index + bar_width, labels)
plt.tick_params(labelsize=fontsize*0.7)
# plt.legend(fontsize=fontsize*0.7, ncol=4, framealpha=0.2)
plt.legend(fontsize=fontsize*0.7, loc='upper right', shadow=False, ncol=4, framealpha=0.2)

plt.tight_layout()
# plt.show()
plt.savefig(f'{pdf_name}.pdf')
plt.savefig(f'{pdf_name}.png')
plt.close()

